﻿#define _CRT_SECURE_NO_WARNINGS 1

// 排序算法
// lambda函数式

#include <iostream>
using namespace std;

#include <vector>
#include <algorithm>

class Solution
{
public:
    vector<string> sortPeople(vector<string>& names, vector<int>& heights)
    {
        // 1. 创建⼀个下标数组
        int n = names.size();
        vector<int> index(n);
        for (int i = 0; i < n; i++) index[i] = i;

        // 2. 对下标进⾏排序
        sort(index.begin(), index.end(), [&](int i, int j)
        {
            return heights[i] > heights[j];
        });

        // 3. 提取结果
        vector<string> ret;
        for (int i : index)
        {
            ret.push_back(names[i]);
        }
        return ret;
    }
};


int main()
{
    vector<string> names = { "Mary", "John", "Emma" };
    vector<int> heights = { 180, 165, 170 };

    auto sortPeople = Solution().sortPeople(names, heights);

    for (const auto& str : sortPeople)
        cout << str << endl;

    return 0;
}